<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *物业项目
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'项目列表'),	
	array('op'=>'edit','title'=>'添加项目'),	
);
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','title','type','fee','remark','status','createtime');
	$list=pdo_getslice('jy_smallquan_fee_classify',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){

		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'title','title'=>'项目名称','type'=>'string'),
			array('name'=>'type','title'=>'收费类型','type'=>'radio','options'=>'type'),
			array('name'=>'fee','title'=>'费用/月（/m²）','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'switch'),
			array('name'=>'createtime','title'=>'添加时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'name','width'=>15,'title'=>'项目名称','type'=>'string'),
		)
	);
	$return['type']=array('按户收费,','按面积收费');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_smallquan_fee_classify',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$return['type']=array('按户收费','按面积收费');
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('name'=>'title','title'=>'项目名称','type'=>'string'),
					array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'type'),
					array('name'=>'fee','title'=>'收费数额/月(/m²)','type'=>'string'),
					array('name'=>'remark','title'=>'备注','type'=>'string'),
					array('name'=>'status','title'=>'启用','type'=>'switch'),
				)
			),
		)
	);
	$return['htmls']=$htmls;
	//print_r($return['lev_name']);exit;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(empty($postdata['title'])){
		exi('请填写项目名称','error');
	}
	if(!$postdata['type']){
		//exi('请填写类型','error');
	}
	if(!$postdata['fee']){
		exi('请填写收费数额','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),	
		'remark'=>trim($postdata['remark']),	
		'type'=>intval($postdata['type']),	
		'fee'=>intval($postdata['fee']),	
		'status'=>intval($postdata['status']),	
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_smallquan_fee_classify',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_smallquan_fee_classify',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_smallquan_fee_classify',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}